package mygui;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.*;

import kernel.Simulator;

public class ActionExit extends AbstractAction{

    MonIHM _ihm;
    
    public ActionExit(MonIHM ihm){
	_ihm = ihm;
	
	putValue(AbstractAction.NAME,"Exit");
	putValue(AbstractAction.SHORT_DESCRIPTION,"Leave the application");
	putValue(AbstractAction.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_Q,KeyEvent.CTRL_MASK ));
	putValue(AbstractAction.SMALL_ICON,UIM.createImageIcon("images/exit.png","Leave the application"));
	
    }
 
    public void actionPerformed(ActionEvent e) {
	String msg = "Do you want to quit simmobil?";
	int n = JOptionPane.showConfirmDialog(_ihm,
					      msg,
					      "simmobil",
					      JOptionPane.YES_NO_OPTION);
	if(n == JOptionPane.YES_OPTION){
	    // TODO : handle save unsaved changes
	    System.exit(0);
	}else{
	    //setVisible(true);
	}
    } 
}
